package com.erp.entity.sale;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.erp.entity.goods.MultipleUnit;

import java.math.BigDecimal;
import java.util.List;

/**
 * @description: 报价单明细实体类
 * @author: lyj
 * @date: 2025/6/30
**/
public class QuotationDetail {
    @ExcelIgnore
    private Integer id;//主键
    @ExcelIgnore
    private Integer goodsId;//商品
    @ExcelIgnore
    private String linkQuotationNumber;//关联报价单编号
    @ExcelIgnore
    private Integer goodsNum;//商品数量
    @ExcelProperty(value = "商品基本数量",index = 2)
    private Integer basicNum;//基本数量
    @ExcelProperty(value = "单价",index = 5)
    private BigDecimal quotePrice;//商品报价单价
    @ExcelIgnore
    private Integer sellwareHouseId;//出货仓库ID
    @ExcelIgnore
    private Integer isGift;//是否为赠品
    @ExcelProperty(value = "税率",index = 6)
    private BigDecimal taxRate;//税率
    @ExcelProperty(value = "含税单价",index = 7)
    private BigDecimal salePriceTax;//含税单价(1+税率)*销售单价
    @ExcelIgnore
    private BigDecimal salePriceTaxDis;//折后含税单价(折后单价+税额)
    @ExcelProperty(value = "税额",index = 8)
    private BigDecimal taxPrice;//税额
    @ExcelProperty(value = "折扣率",index = 9)
    private BigDecimal discountRate;//折扣率
    @ExcelProperty(value = "折扣额",index = 10)
    private BigDecimal discountNum;//折扣额
    @ExcelIgnore
    private BigDecimal salePriceDis;//折后单价
    @ExcelIgnore
    private BigDecimal totalPriceDis;//折后金额(销售单价*数量-折扣金额)
    @ExcelProperty(value = "价税合计",index = 11)
    private BigDecimal priceAndTax;//价税合计(折后含税单价*数量)
    @ExcelProperty(value = "商品备注",index = 12)
    private String goodsRemarks;//商品备注
    @ExcelIgnore
    private Integer companyId;//公司ID
    @ExcelIgnore
    private Integer basicUnitId;//基本单位ID
    @ExcelIgnore
    private Integer multipleUnitId;//多单位ID
    @ExcelIgnore
    private String linkSaleOrderNumber;//关联销货订单编号
    @ExcelIgnore
    private String linkSaleNumber;//关联销货单编号

//    ----------------不在数据库中的字段--------------------------------
    @ExcelIgnore
    private String unitName;//商品单位名称
    @ExcelProperty(value = "商品名称",index = 1)
    private String goodsName;//商品名称
    @ExcelIgnore
    private String goodsImage;//商品图片
    @ExcelIgnore
    private String goodsAttribute;//商品属性
    @ExcelProperty(value = "商品品牌",index = 4)
    private String goodsBrand;//商品品牌

    @ExcelProperty(value = "基本单位名称",index = 3)
    private String basicUnitName;//基本单位名称
    @ExcelIgnore
    private List<MultipleUnit> multipleUnitList;
    @ExcelIgnore
    private String multipleUnitName;//多单位名称
    @ExcelIgnore
    private String sellwareHouseName;//出库仓库名称

    public QuotationDetail(){}
    public QuotationDetail(BigDecimal quotePrice){
        this.quotePrice = quotePrice;
        setBasicNum(1);
        setGoodsNum(1);
        setTaxRate(BigDecimal.ZERO);
        setTaxPrice(BigDecimal.ZERO);
        setDiscountRate(BigDecimal.ZERO);
        setDiscountNum(BigDecimal.ZERO);
        setSalePriceTax(getQuotePrice());
        setSalePriceTaxDis(getQuotePrice());
        setSalePriceDis(getQuotePrice());
        setTotalPriceDis(getQuotePrice());
        setPriceAndTax(getQuotePrice().multiply(BigDecimal.valueOf(getGoodsNum())));
    }

    public QuotationDetail(BigDecimal quotePrice,BigDecimal taxRate,
                           BigDecimal discountRate,Integer goodsNum,
                           Integer basicNum){
        setGoodsNum(goodsNum);
        setBasicNum(basicNum);
        setQuotePrice(quotePrice);


        //设置税率相关信息
        setTaxRate(taxRate);
        setTaxPrice(BigDecimal.valueOf(getBasicNum()).multiply(quotePrice).multiply(getTaxRate().multiply(BigDecimal.valueOf(0.01))));//计算税额
        setSalePriceTax(quotePrice.add(quotePrice.multiply(taxRate.multiply(BigDecimal.valueOf(0.01)))));//设置含税单价

        //设置折扣相关信息
        setDiscountRate(discountRate);//设置商品折扣率
        setDiscountNum(BigDecimal.valueOf(basicNum)
                .multiply(discountRate.multiply(BigDecimal.valueOf(0.01)))
                .multiply(quotePrice));//设置商品折扣额
        setSalePriceDis(discountRate.multiply(quotePrice).multiply(BigDecimal. valueOf(0.01)).add(quotePrice)); //设置商品折后单价
        setTotalPriceDis(getSalePriceDis().multiply(BigDecimal.valueOf(getBasicNum())));//设置商品折后金额
        setSalePriceTaxDis(getSalePriceDis().add(quotePrice.multiply(getTaxRate().multiply(BigDecimal.valueOf(0.01)))));//设置商品折后含税单价
        //设置商品价税合计
        setPriceAndTax(getSalePriceTaxDis().multiply(BigDecimal.valueOf(basicNum)));
    }
    public void setBasicPriceInfo(BigDecimal quotePrice){
        this.quotePrice = quotePrice;
        setBasicNum(1);
        setGoodsNum(1);
        setTaxRate(BigDecimal.ZERO);
        setTaxPrice(BigDecimal.ZERO);
        setDiscountRate(BigDecimal.ZERO);
        setDiscountNum(BigDecimal.ZERO);
        setSalePriceTax(getQuotePrice());
        setSalePriceTaxDis(getQuotePrice());
        setSalePriceDis(getQuotePrice());
        setTotalPriceDis(getQuotePrice());
        setPriceAndTax(getQuotePrice().multiply(BigDecimal.valueOf(getGoodsNum())));
    }

    public void  setBasicInfo(BigDecimal quotePrice,Integer goodsNum,Integer basicNum){
        this.quotePrice = quotePrice;
        setBasicNum(basicNum);
        setGoodsNum(goodsNum);
        setTaxRate(BigDecimal.ZERO);
        setTaxPrice(BigDecimal.ZERO);
        setDiscountRate(BigDecimal.ZERO);
        setDiscountNum(BigDecimal.ZERO);
        setSalePriceTax(getQuotePrice());
        setSalePriceTaxDis(getQuotePrice());
        setSalePriceDis(getQuotePrice());
        setTotalPriceDis(getQuotePrice());
        setPriceAndTax(getQuotePrice().multiply(BigDecimal.valueOf(getGoodsNum())));
    }

    public String getLinkSaleOrderNumber() {
        return linkSaleOrderNumber;
    }

    public void setLinkSaleOrderNumber(String linkSaleOrderNumber) {
        this.linkSaleOrderNumber = linkSaleOrderNumber;
    }

    public String getLinkSaleNumber() {
        return linkSaleNumber;
    }

    public void setLinkSaleNumber(String linkSaleNumber) {
        this.linkSaleNumber = linkSaleNumber;
    }

    public List<MultipleUnit> getMultipleUnitList() {
        return multipleUnitList;
    }

    public void setMultipleUnitList(List<MultipleUnit> multipleUnitList) {
        this.multipleUnitList = multipleUnitList;
    }

    public String getSellwareHouseName() {
        return sellwareHouseName;
    }

    public void setSellwareHouseName(String sellwareHouseName) {
        this.sellwareHouseName = sellwareHouseName;
    }


    public Integer getBasicUnitId() {
        return basicUnitId;
    }

    public void setBasicUnitId(Integer basicUnitId) {
        this.basicUnitId = basicUnitId;
    }

    public String getBasicUnitName() {
        return basicUnitName;
    }

    public void setBasicUnitName(String basicUnitName) {
        this.basicUnitName = basicUnitName;
    }

    public String getGoodsBrand() {
        return goodsBrand;
    }

    public void setGoodsBrand(String goodsBrand) {
        this.goodsBrand = goodsBrand;
    }

    public Integer getBasicNum() {
        return basicNum;
    }

    public void setBasicNum(Integer basicNum) {
        this.basicNum = basicNum;
    }

    public String getUnitName() {
        return unitName;
    }



    public void setUnitName(String unitName) {
        this.unitName = unitName;
    }

    public String getGoodsName() {
        return goodsName;
    }

    public void setGoodsName(String goodsName) {
        this.goodsName = goodsName;
    }

    public String getGoodsImage() {
        return goodsImage;
    }

    public void setGoodsImage(String goodsImage) {
        this.goodsImage = goodsImage;
    }

    public String getGoodsAttribute() {
        return goodsAttribute;
    }

    public void setGoodsAttribute(String goodsAttribute) {
        this.goodsAttribute = goodsAttribute;
    }

    public BigDecimal getSalePriceTaxDis() {
        return salePriceTaxDis;
    }

    public void setSalePriceTaxDis(BigDecimal salePriceTaxDis) {
        this.salePriceTaxDis = salePriceTaxDis;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getGoodsId() {
        return goodsId;
    }

    public void setGoodsId(Integer goodsId) {
        this.goodsId = goodsId;
    }

    public String getLinkQuotationNumber() {
        return linkQuotationNumber;
    }

    public void setLinkQuotationNumber(String linkQuotationNumber) {
        this.linkQuotationNumber = linkQuotationNumber;
    }

    public Integer getGoodsNum() {
        return goodsNum;
    }

    public void setGoodsNum(Integer goodsNum) {
        this.goodsNum = goodsNum;
    }



    public BigDecimal getQuotePrice() {
        return quotePrice;
    }

    public void setQuotePrice(BigDecimal quotePrice) {
        this.quotePrice = quotePrice;
    }

    public Integer getSellwareHouseId() {
        return sellwareHouseId;
    }

    public void setSellwareHouseId(Integer sellwareHouseId) {
        this.sellwareHouseId = sellwareHouseId;
    }

    public Integer getMultipleUnitId() {
        return multipleUnitId;
    }

    public void setMultipleUnitId(Integer multipleUnitId) {
        this.multipleUnitId = multipleUnitId;
    }

    public String getMultipleUnitName() {
        return multipleUnitName;
    }

    public void setMultipleUnitName(String multipleUnitName) {
        this.multipleUnitName = multipleUnitName;
    }

    public Integer getIsGift() {
        return isGift;
    }

    public void setIsGift(Integer isGift) {
        this.isGift = isGift;
    }

    public BigDecimal getTaxRate() {
        return taxRate;
    }

    public void setTaxRate(BigDecimal taxRate) {
        this.taxRate = taxRate;
    }

    public BigDecimal getSalePriceTax() {
        return salePriceTax;
    }

    public void setSalePriceTax(BigDecimal salePriceTax) {
        this.salePriceTax = salePriceTax;
    }

    public BigDecimal getTaxPrice() {
        return taxPrice;
    }

    public void setTaxPrice(BigDecimal taxPrice) {
        this.taxPrice = taxPrice;
    }

    public BigDecimal getDiscountRate() {
        return discountRate;
    }

    public void setDiscountRate(BigDecimal discountRate) {
        this.discountRate = discountRate;
    }

    public BigDecimal getDiscountNum() {
        return discountNum;
    }

    public void setDiscountNum(BigDecimal discountNum) {
        this.discountNum = discountNum;
    }

    public BigDecimal getSalePriceDis() {
        return salePriceDis;
    }

    public void setSalePriceDis(BigDecimal salePriceDis) {
        this.salePriceDis = salePriceDis;
    }

    public BigDecimal getTotalPriceDis() {
        return totalPriceDis;
    }

    public void setTotalPriceDis(BigDecimal totalPriceDis) {
        this.totalPriceDis = totalPriceDis;
    }

    public BigDecimal getPriceAndTax() {
        return priceAndTax;
    }

    public void setPriceAndTax(BigDecimal priceAndTax) {
        this.priceAndTax = priceAndTax;
    }

    public String getGoodsRemarks() {
        return goodsRemarks;
    }

    public void setGoodsRemarks(String goodsRemarks) {
        this.goodsRemarks = goodsRemarks;
    }

    public Integer getCompanyId() {
        return companyId;
    }

    public void setCompanyId(Integer companyId) {
        this.companyId = companyId;
    }
}